import apis from "../../http/apis/apis";
export default {
    namespaced: true,
    state: {
        ordersArr: [],
        currentPage: 1,
        pageSize: 5,
        total: 100,
        state: '',//订单状态选择
    },
    mutations: {
        changeOrdersArr(state, data) {
            state.ordersArr = data.data;
            state.total = data.total;
        },
        changePageSize(state, data) {
            state.pageSize = data;
        },
        changecurrentPage(state, data) {
            state.currentPage = data;
        },
        changeState(state, val) {
            state.state = val;
        }
    },
    actions: {
        //获取订单列表
        async getOrders(context) {
            var data = {
                pageSize: context.state.pageSize,
                currentPage: context.state.currentPage,
                state: context.state.state
            }
            const msg = await apis.orders.getOrders(data);
            if (msg.data.state == 1) {
                context.commit('changeOrdersArr', msg.data);
            }
        },
        //删除订单
        async delOrders(context, id) {
            var data = { _id: id }
            const msg = await apis.orders.delOrders(data)
        },
        //查找订单
        async findOrders(context, data) {
            const msg = await apis.orders.findOrders(data);

            if (msg.data.state == 1) {
                context.commit('changeOrdersArr', msg.data.data);
            }

        },



    },
}